package cn.cnsuh.q696_countBinarySubstrings;

import java.util.ArrayList;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        System.out.println("countBinarySubstrings(s) = " + countBinarySubstrings(s));
        System.out.println("fun2(s) = " + fun2(s));
    }

    static int fun2(String s) {
        int cnt = 0, last = 0, ans = 0;
        for (int i = 0; i < s.length(); i++) {
            if (i == 0) {
                cnt++;
                continue;
            }
            if (s.charAt(i) == s.charAt(i - 1)) {
                cnt++;
            } else {
                if (last != 0) {
                    ans += Math.min(last, cnt);
                }
                last = cnt;
                cnt = 1;
            }
        }
        ans += Math.min(last, cnt);
        return ans;
    }

    static int countBinarySubstrings(String s) {
        ArrayList<Integer> list = new ArrayList<>();
        int len = s.length();
        int cnt = 0;
        for (int i = 0; i < len; i++) {
            if (i == 0) {
                cnt++;
                continue;
            }
            if (s.charAt(i) == s.charAt(i - 1)) {
                cnt++;
            } else {
                list.add(cnt);
                cnt = 1;
            }
        }
        list.add(cnt);
        int ans = 0;
        for (int i = 1; i < list.size(); i++) {
            ans += Math.min(list.get(i - 1), list.get(i));
        }
        return ans;
    }
}
